package com.gxwy.shenzhou;

public class KaihuResponse implements StringHandler{
	private KaiHuHeaderResponse header;
	private String yddh;
	public static final int YDDH_LEN=15;
	public static final int YDDH_FLAG=2;
	private String zz_ed;
	public static final int ZZ_ED_LEN=15;
	public static final int ZZ_ED_FLAG=2;
	private String csbm;
	public static final int CSBM_LEN=8;
	public static final int CSBM_FLAG=2;
	private String clm;
	public static final int CLM_LEN=8;
	public static final int CLM_FLAG=2;
	private String flbz0;
	public static final int FLBZ0_LEN=1;
	public static final int FLBZ0_FLAG=2;
	private String flbz1;
	public static final int FLBZ1_LEN=1;
	public static final int FLBZ1_FLAG=2;
	private String flbz2;
	public static final int FLBZ2_LEN=1;
	public static final int FLBZ2_FLAG=2;
	private String flbz3;
	public static final int FLBZ3_LEN=1;
	public static final int FLBZ3_FLAG=2;
	private String flbz4;
	public static final int FLBZ4_LEN=1;
	public static final int FLBZ4_FLAG=2;
	private String flbz5;
	public static final int FLBZ5_LEN=1;
	public static final int FLBZ5_FLAG=2;
	private String flbz6;
	public static final int FLBZ6_LEN=1;
	public static final int FLBZ6_FLAG=2;
	private String flbz7;
	public static final int FLBZ7_LEN=1;
	public static final int FLBZ7_FLAG=2;
	public static final int TOTAL_LEN=YDDH_LEN+ZZ_ED_LEN+CSBM_LEN+CLM_LEN+FLBZ0_LEN+FLBZ1_LEN+
			FLBZ2_LEN+FLBZ3_LEN+FLBZ4_LEN+FLBZ5_LEN+FLBZ6_LEN+FLBZ7_LEN;
	private int reallen=0;
	public KaiHuHeaderResponse getHeader() {
		return header;
	}
	public void setHeader(KaiHuHeaderResponse header) {
		this.header = header;
	}
	public String getYddh() {
		return yddh;
	}
	public void setYddh(String yddh) throws Exception {
		if(yddh==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(yddh.getBytes("gbk").length<YDDH_LEN){
			this.yddh=Supply.supply(yddh, YDDH_FLAG, YDDH_LEN);
		}else if(yddh.getBytes("gbk").length>YDDH_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.yddh = yddh;			
		}
	}
	public String getZz_ed() {
		return zz_ed;
	}
	public void setZz_ed(String zz_ed) throws Exception {
		if(zz_ed==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zz_ed.getBytes("gbk").length<ZZ_ED_LEN){
			this.zz_ed=Supply.supply(zz_ed, ZZ_ED_FLAG, ZZ_ED_LEN);
		}else if(zz_ed.getBytes("gbk").length>ZZ_ED_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.zz_ed = zz_ed;			
		}
	}
	public String getCsbm() {
		return csbm;
	}
	public void setCsbm(String csbm) throws Exception {
		if(csbm==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(csbm.getBytes("gbk").length<CSBM_LEN){
			this.csbm=Supply.supply(csbm, CSBM_FLAG, CSBM_LEN);
		}else if(csbm.getBytes("gbk").length>CSBM_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.csbm = csbm;			
		}
	}
	public String getClm() {
		return clm;
	}
	public void setClm(String clm) throws Exception {
		if(clm==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(clm.getBytes("gbk").length<CLM_LEN){
			this.clm=Supply.supply(clm, CLM_FLAG, CLM_LEN);
		}else if(clm.getBytes("gbk").length>CLM_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.clm = clm;			
		}
	}
	public String getFlbz0() {
		return flbz0;
	}
	public void setFlbz0(String flbz0) throws Exception {
		if(flbz0==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz0.getBytes("gbk").length<FLBZ0_LEN){
			this.flbz0=Supply.supply(flbz0, FLBZ0_FLAG, FLBZ0_LEN);
		}else if(flbz0.getBytes("gbk").length>FLBZ0_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz0 = flbz0;			
		}
	}
	public String getFlbz1() {
		return flbz1;
	}
	public void setFlbz1(String flbz1) throws Exception {
		if(flbz1==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz1.getBytes("gbk").length<FLBZ1_LEN){
			this.flbz0=Supply.supply(flbz1, FLBZ1_FLAG, FLBZ1_LEN);
		}else if(flbz1.getBytes("gbk").length>FLBZ1_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz1 = flbz1;			
		}
	}
	public String getFlbz2() {
		return flbz2;
	}
	public void setFlbz2(String flbz2) throws Exception {
		if(flbz2==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz2.getBytes("gbk").length<FLBZ2_LEN){
			this.flbz0=Supply.supply(flbz2, FLBZ2_FLAG, FLBZ2_LEN);
		}else if(flbz2.getBytes("gbk").length>FLBZ2_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz2 = flbz2;			
		}
	}
	public String getFlbz3() {
		return flbz3;
	}
	public void setFlbz3(String flbz3) throws Exception {
		if(flbz3==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz3.getBytes("gbk").length<FLBZ3_LEN){
			this.flbz0=Supply.supply(flbz3, FLBZ3_FLAG, FLBZ3_LEN);
		}else if(flbz3.getBytes("gbk").length>FLBZ3_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz3 = flbz3;			
		}
	}
	public String getFlbz4() {
		return flbz4;
	}
	public void setFlbz4(String flbz4) throws Exception {
		if(flbz4==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz4.getBytes("gbk").length<FLBZ4_LEN){
			this.flbz0=Supply.supply(flbz4, FLBZ4_FLAG, FLBZ4_LEN);
		}else if(flbz4.getBytes("gbk").length>FLBZ4_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz4 = flbz4;			
		}
	}
	public String getFlbz5() {
		return flbz5;
	}
	public void setFlbz5(String flbz5) throws Exception {
		if(flbz5==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz5.getBytes("gbk").length<FLBZ5_LEN){
			this.flbz0=Supply.supply(flbz5, FLBZ5_FLAG, FLBZ5_LEN);
		}else if(flbz5.getBytes("gbk").length>FLBZ5_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz5 = flbz5;			
		}
	}
	public String getFlbz6() {
		return flbz6;
	}
	public void setFlbz6(String flbz6) throws Exception {
		if(flbz6==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz6.getBytes("gbk").length<FLBZ6_LEN){
			this.flbz0=Supply.supply(flbz6, FLBZ6_FLAG, FLBZ6_LEN);
		}else if(flbz6.getBytes("gbk").length>FLBZ6_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz6 = flbz6;			
		}
	}
	public String getFlbz7() {
		return flbz7;
	}
	public void setFlbz7(String flbz7) throws Exception {
		if(flbz7==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(flbz7.getBytes("gbk").length<FLBZ7_LEN){
			this.flbz0=Supply.supply(flbz7, FLBZ7_FLAG, FLBZ7_LEN);
		}else if(flbz7.getBytes("gbk").length>FLBZ7_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.flbz7 = flbz7;			
		}
	}
	
	@Override
	public String toString() {
		return "KaihuResponse [header=" + header.toString() + ", yddh=" + yddh
				+ ", zz_ed=" + zz_ed + ", csbm=" + csbm + ", clm=" + clm
				+ ", flbz0=" + flbz0 + ", flbz1=" + flbz1 + ", flbz2=" + flbz2
				+ ", flbz3=" + flbz3 + ", flbz4=" + flbz4 + ", flbz5=" + flbz5
				+ ", flbz6=" + flbz6 + ", flbz7=" + flbz7 + ", reallen="
				+ reallen + "]";
	}
	public String build() throws Exception{
		if(this.getHeader()==null){
			throw new Exception("Header is null");
		}
		if(this.getYddh()==null){
			this.setYddh("");
		}
		if(this.getZz_ed()==null){
			this.setZz_ed("");
		}
		if(this.getCsbm()==null){
			this.setCsbm("");
		}
		if(this.getClm()==null){
			this.setClm("");
		}
		if(this.getFlbz0()==null){
			this.setFlbz0("");
		}
		if(this.getFlbz1()==null){
			this.setFlbz1("");
		}
		if(this.getFlbz2()==null){
			this.setFlbz2("");
		}
		if(this.getFlbz3()==null){
			this.setFlbz3("");
		}
		if(this.getFlbz4()==null){
			this.setFlbz4("");
		}
		if(this.getFlbz5()==null){
			this.setFlbz5("");
		}
		if(this.getFlbz6()==null){
			this.setFlbz6("");
		}
		if(this.getFlbz7()==null){
			this.setFlbz7("");
		}
		Integer totallen=KaiHuHeaderResponse.TOTAL_LEN+TOTAL_LEN-KaiHuHeaderResponse.LEN_LEN;
		this.getHeader().setLen(totallen.toString());
		return this.getHeader().build()+this.getYddh()+this.getZz_ed()+this.getCsbm()+this.getClm()+this.getFlbz0()+this.getFlbz1()+
				this.getFlbz2()+this.getFlbz3()+this.getFlbz4()+this.getFlbz5()+this.getFlbz6()+this.getFlbz7();
	}
	
	public void parse(String str) throws Exception{
		if(str==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(str.getBytes("gbk").length<KaiHuHeaderResponse.TOTAL_LEN+TOTAL_LEN){
			Exception e=new Exception("Invalid request");
			 throw e;
		}else{
			String headerLen=SplitString.splitString(str,reallen, reallen+KaiHuHeaderResponse.TOTAL_LEN);
			reallen+=KaiHuHeaderResponse.TOTAL_LEN;
			KaiHuHeaderResponse hr=new KaiHuHeaderResponse();
			hr.parse(headerLen);
			this.setHeader(hr);
			this.setYddh(SplitString.splitString(str,reallen, reallen+YDDH_LEN));
			reallen+=YDDH_LEN;
			this.setZz_ed(SplitString.splitString(str,reallen, reallen+ZZ_ED_LEN));
			reallen+=ZZ_ED_LEN;
			this.setCsbm(SplitString.splitString(str,reallen, reallen+CSBM_LEN));
			reallen+=CSBM_LEN;
			this.setClm(SplitString.splitString(str,reallen, reallen+CLM_LEN));
			reallen+=CLM_LEN;
			this.setFlbz0(SplitString.splitString(str,reallen, reallen+FLBZ0_LEN));
			reallen+=FLBZ0_LEN;
			this.setFlbz1(SplitString.splitString(str,reallen, reallen+FLBZ1_LEN));
			reallen+=FLBZ1_LEN;
			this.setFlbz2(SplitString.splitString(str,reallen, reallen+FLBZ2_LEN));
			reallen+=FLBZ2_LEN;
			this.setFlbz3(SplitString.splitString(str,reallen, reallen+FLBZ3_LEN));
			reallen+=FLBZ3_LEN;
			this.setFlbz4(SplitString.splitString(str,reallen, reallen+FLBZ4_LEN));
			reallen+=FLBZ4_LEN;
			this.setFlbz5(SplitString.splitString(str,reallen, reallen+FLBZ5_LEN));
			reallen+=FLBZ5_LEN;
			this.setFlbz6(SplitString.splitString(str,reallen, reallen+FLBZ6_LEN));
			reallen+=FLBZ6_LEN;
			this.setFlbz7(SplitString.splitString(str,reallen, reallen+FLBZ7_LEN));
			reallen+=FLBZ7_LEN;
		}
	}
}
